<button class="btn btn-primary" type="button" onclick="addVender()">新增</button>

<table class="table" id="userListDiv">
    <thead>
    <tr>
        <th>序号</th>
        <th>供应商编号</th>
        <th>名称</th>
        <th>密码</th>
        <th>联系人</th>
        <th>地址</th>
        <th>邮政编码</th>
        <th>电话</th>
        <th>传真</th>
        <th>创建时间</th>
        <th colspan="2">操作</th>
    </tr>
    </thead>
    <tbody id="tableBody"></tbody>
</table>
<div>
    <ul id="page">分页</ul>
</div>

<script id="VenderListTemplate" type="text/html">
    {{each data value index}}
    <tr>
        <td>{{index+1}}</td>
        <td>{{value.venderCode}}</td>
        <td>{{value.name}}</td>
        <td>{{value.password}}</td>
        <td>{{value.contactor}}</td>
        <td>{{value.address}}</td>
        <td>{{value.postCode}}</td>
        <td>{{value.tel}}</td>
        <td>{{value.fax}}</td>
        <td>{{value.createDate}}</td>
        <td><input value="删除" type="button"  onclick="return del('{{value.venderCode}}')"></td>
        <td><input value="修改" type="button"  onclick="update('{{value.venderCode}}')"></td>
    </tr>
    {{/each}}
</script>

<script>
    $(function () {
        showPage({
            currentPage: 1,
            pageSize: 2,
            url: '/getAllVender',
            templateId: 'VenderListTemplate',
            contentId: 'tableBody',
            params: {
                id: 1
            }
        })
    })
    function del(obj) {
        if(confirm("确认删除？")){
            Ajax.post(
                "/deleteVender",
                {venderCode:obj},
                function (result) {
                    show('po/vender.html')
                    alert(result.msg)
                }
            )
        }else{
            show('po/vender.html')
            return false;
        }

    }
    function update(obj) {
        Ajax.getHtml('po/venderUpdate.html', function (html) {
            layer.open({
                type: 1,
                title: '修改供应商信息',
                area: ['600px'],
                content: html,
                btn: ['确认', '取消'],
                yes: function () {
                    updatevender()
                },
                btn2: function () {
                    console.log('取消修改供应商信息')
                }
            })
        })
        Ajax.post(
            "selectByVenderCode",
            {venderCode:obj},
            function (result) {
                data=result.data;
                $("#venderCode").val(data.venderCode);
                $("#password").val(data.password);
                $("#vendername").val(data.name);
                $("#contactor").val(data.contactor);
                $("#address").val(data.address);
                $("#postcode").val(data.postCode);
                $("#tel").val(data.tel);
                $("#fax").val(data.fax);
                $("#createDate").val(data.createDate);
            }
        )
    }
</script>
